package com.itheima.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
    public static final String EXCHANGE = "myexchange";
    public static final String QUEUE = "myqueue";
    public static final String ROUTING_KEY = "fire";
    
    /**
     * 交换机
     */
    @Bean(EXCHANGE)
    public DirectExchange exchange() {
        return ExchangeBuilder.directExchange(EXCHANGE).durable(true).build();
    }

    /**
     * 队列
     */
    @Bean(QUEUE)
    public Queue queue() {
        return new Queue(QUEUE);
    }

    /**
     * 将队列和交换机绑定
     */
    @Bean
    public Binding binding(@Qualifier(QUEUE) Queue queue, @Qualifier(EXCHANGE) DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY);
    }
}